/*
 * @Description: mark
 * @Author: wangwangwang
 * @Date: 2020-07-09 09:11:34
 * @LastEditors: wangwangwang
 * @LastEditTime: 2020-08-06 17:27:28
 */
/**
 * Number formatting
 * like 10000 => 10k
 * @param {number} num
 * @param {number} digits
 */
export function numberFormatter(num, digits) {
  const si = [{
      value: 1E18,
      symbol: 'E'
    },
    {
      value: 1E15,
      symbol: 'P'
    },
    {
      value: 1E12,
      symbol: 'T'
    },
    {
      value: 1E9,
      symbol: 'G'
    },
    {
      value: 1E6,
      symbol: 'M'
    },
    {
      value: 1E3,
      symbol: 'k'
    }
  ]
  for (let i = 0; i < si.length; i++) {
    if (num >= si[i].value) {
      return (num / si[i].value).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

/**
 * 10000 => "10,000"
 * @param {number} num
 */
export function toThousandFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}


export function toStr(data) {
  return (JSON.stringify(data))
}
/**
 * @Description: 格式化table数据
 * @Param: 
 * @Author: wangwangwang
 */
export function fromatTable(List, data, name, id) {
  for (let i = 0; i < List.length; i++) {
    if (List[i][id] === data) {

      return List[i][name]
    }
  }
  return '无数据'
}